AirBNB Data Set Analysis

Import Libraries

In [1]:
import pandas as pd
import geopandas as gp
import matplotlib
import matplotlib.pyplot as plt
import requests
import os
import fiona
import numpy as np
import shapely
from datetime import datetime
from shapely.geometry import Point

Convert data stored in .csv files in cwd into dictionary objects

In [2]:
listings = pd.read_csv("listings.csv")
review = pd.read_csv("reviews.csv")
neighbourhoods = pd.read_csv("neighbourhoods.csv")

Creating map given with neighbourhoods.geojson

In [3]:
# Stores geo data
suburbs = gp.read_file("neighbourhoods.geojson")


# Scales map plot size
%matplotlib inline

# Updates matplotlib fontsize
plt.rcParams.update({'font.size': 22})

# Updates matplotlib graph display size
plt.rcParams['figure.figsize'] = (35, 50)
In [4]:
# Adds a centroid / small circle in the middle of a geometry shape
# Necessary to plot location names in the map
def add_centroid(row):
    return row.geometry.centroid
In [5]:
# Function to add a geometry column into listings 
# storing a Shapely Point
def newGeometry(data_list):
    geo_list = []

    for x in range(len(data_list["longitude"])):
        point = Point(data_list["longitude"][x], data_list["latitude"][x])
        geo_list.append(point)

    data_list["geometry"] = geo_list;

    return data_list
In [6]:
# Set centroid to print location name later
suburbs["centroid"] = suburbs.apply(add_centroid, axis=1)

# Update listings with geometry column for plotting purposes
listings = newGeometry(listings)

# Converts listings DataFrame into Geopanda DataFrame and store it in geo_listings
# geo_listings stores geometry information of available air_bnb rental locations
geo_listings = gp.GeoDataFrame(listings)

# Plot Map
suburbs.plot(cmap="cool")

# Prints suburb name
for idx, row in suburbs.iterrows():
    plt.annotate(s=row.neighbourhood, xy=tuple(row.centroid.coords)[0], 
                 horizontalalignment='center')
    
plt.figtext(.5,0.8,"NSW Suburb Map",fontsize=40,ha='center')
Out[6]:
Text(0.5, 0.8, 'NSW Suburb Map')

Plots all available AirBnb Rental Locations

In [7]:
# IMPORTANT SETUP to ensure we are able to plot two DataFrame in the same graph
f, ax = plt.subplots(1, figsize=(40, 50))
ax.set_axis_off()
plt.axis('equal')
suburbs.plot(ax=ax, cmap='cool', linewidth=0.5)
geo_listings.plot(markersize=10, categorical=True, legend=True, ax=ax, edgecolor='black');

plt.figtext(.5,.85,"Available AirBnb Rentals in NSW",fontsize=50,ha='center')
Out[7]:
Text(0.5, 0.85, 'Available AirBnb Rentals in NSW')

Graph to display Types of AirBnB Rentals

In [8]:
# Function to create a list of dictionaries containing
# different Room Type Rentals and the total count of each
# available room type and price
def createRoomList(main_data):
    
    # List to return, contains information for Room Types 
    rlist = []
    
    for x in range(len(main_data["room_type"])):
        
        if checkExistingRoom(main_data["room_type"][x], rlist) == 0:
            new_dict = {
                "rtype" : main_data["room_type"][x],
                "count" : 1
            }
            rlist.append(new_dict)
            
        else:
            rlist = addRoomCount(rlist, main_data["room_type"][x])
            
        
        
    return rlist


# Function to add room count to associated room type
def addRoomCount(rlist, rtype):
    for x in rlist:
        if x["rtype"] == rtype:
            x["count"] += 1
            
    return rlist


# Function to check whether a Room Type exist already in a given
# list (rlist in this case), if exist return 1 else return 0
def checkExistingRoom(rtype, rlist):
    
    # For list is empty
    if not rlist:
        return 0
    
    for x in rlist:
        if x["rtype"] == rtype:
            return 1
    
    return 0
In [9]:
room_data = createRoomList(listings)
room_data = pd.DataFrame(room_data)

# numply plot stuff
# Set number of data points to plot with "nump"
nump_row = np.arange(len(room_data))
plt.bar(nump_row, room_data["count"])
plt.xticks(nump_row, room_data["rtype"])
Out[9]:
([<matplotlib.axis.XTick at 0x7f513baf36a0>,
  <matplotlib.axis.XTick at 0x7f513baf4f98>,
  <matplotlib.axis.XTick at 0x7f513baf4438>],
 <a list of 3 Text xticklabel objects>)

Plot Avg Room Price for a Room Type & Associated Suburb

In [10]:
# Store all available room type into rt_list
rt_list = room_data["rtype"]

# Function to sot listings into suburbs associated with a room type
def sortSuburb(main_data, rt):
    
    rlist = []
    
    for x in range(len(main_data["room_type"])):

        if checkExistingSuburb(main_data["neighbourhood"][x], rlist) == 0 and main_data["room_type"][x] == rt:
            new_dict = {
                "location" : main_data["neighbourhood"][x],
                "price": round(main_data["price"][x]/main_data["minimum_nights"][x]),
                "count": 1,
                "rtype": main_data["room_type"][x]
            }
            
            rlist.append(new_dict)
        
        elif checkExistingSuburb(main_data["neighbourhood"][x], rlist) == 1 and main_data["room_type"][x] == rt:
            days = main_data["minimum_nights"][x]
            rlist = addSuburbCount(rlist, main_data["neighbourhood"][x], main_data["price"][x], days)
            
    rlist = avgPrice(rlist)
            
    return rlist


# Function to count average price for different suburbs & associated room type
def avgPrice(rlist):
    
    for x in rlist:
        x["price"] = round(x["price"] / x["count"])
            
    return rlist
    
    
# Function to add room count & price to associated room type
def addSuburbCount(rlist, suburb, price, days):
    
    daily_price = round(price/days)
    
    for x in rlist:
        if x["location"] == suburb:
            x["count"] += 1
            x["price"] += daily_price
            
    return rlist


# Function to check whether a Suburb exist already in a given
# list (rlist in this case), if exist return 1 else return 0
def checkExistingSuburb(loc, rlist):
    
    # For list is empty
    if not rlist:
        return 0
    
    for x in rlist:
        if x["location"] == loc:
            return 1
    
    return 0
    
In [11]:
tmp = sortSuburb(listings, rt_list[0])
print_data = pd.DataFrame(tmp)
print_data.rename(columns={"count": "Available Rooms", "location": "Location", "price": "Avg. Price per night", "rtype": "Room Type"}, inplace=True)
print_data
Out[11]:
Location Avg. Price per night Available Rooms Room Type
0 Sydney 69.0 3210 Private room
1 Woollahra 54.0 527 Private room
2 Lane Cove 67.0 123 Private room
3 Marrickville 42.0 627 Private room
4 Hornsby 51.0 192 Private room
5 Waverley 47.0 1813 Private room
6 North Sydney 59.0 412 Private room
7 Sutherland Shire 67.0 150 Private room
8 Ku-Ring-Gai 59.0 154 Private room
9 Strathfield 47.0 110 Private room
10 Pittwater 103.0 124 Private room
11 Randwick 47.0 1409 Private room
12 Blacktown 50.0 229 Private room
13 Auburn 61.0 164 Private room
14 Canada Bay 62.0 213 Private room
15 The Hills Shire 60.0 199 Private room
16 Mosman 73.0 116 Private room
17 Willoughby 50.0 205 Private room
18 Parramatta 54.0 322 Private room
19 Leichhardt 53.0 301 Private room
20 Warringah 49.0 454 Private room
21 Manly 68.0 481 Private room
22 Holroyd 36.0 87 Private room
23 Penrith 81.0 61 Private room
24 Ryde 54.0 311 Private room
25 Bankstown 52.0 173 Private room
26 Rockdale 49.0 419 Private room
27 Hunters Hill 92.0 25 Private room
28 Ashfield 42.0 155 Private room
29 Botany Bay 56.0 341 Private room
30 Burwood 53.0 146 Private room
31 Canterbury 52.0 194 Private room
32 Hurstville 57.0 146 Private room
33 City Of Kogarah 52.0 131 Private room
34 Campbelltown 53.0 49 Private room
35 Camden 71.0 26 Private room
36 Fairfield 46.0 47 Private room
37 Liverpool 47.0 78 Private room
In [12]:
# Plotting avg_cost_data on a graph
plot_data = pd.DataFrame(tmp)
plot_data
plt.plot(plot_data["location"], plot_data["price"])
plt.xticks(plot_data["location"], rotation='vertical', fontsize=25)
plt.ylabel("Price", fontsize=50, labelpad=50)
plt.title("Private Room Avg. Price", fontsize=50, pad=30)
plt.figure(figsize=(10,10))
Out[12]:
<Figure size 720x720 with 0 Axes>
<Figure size 720x720 with 0 Axes>
In [13]:
tmp = sortSuburb(listings, rt_list[1])
print_data = pd.DataFrame(tmp)
print_data.rename(columns={"count": "Available Rooms", "location": "Location", "price": "Avg. Price per night", "rtype": "Room Type"}, inplace=True)
print_data
Out[13]:
Location Avg. Price per night Available Rooms Room Type
0 Manly 103.0 1363 Entire home/apt
1 Leichhardt 107.0 683 Entire home/apt
2 North Sydney 91.0 986 Entire home/apt
3 Waverley 110.0 3507 Entire home/apt
4 Sydney 111.0 6235 Entire home/apt
5 Mosman 118.0 415 Entire home/apt
6 Pittwater 204.0 1051 Entire home/apt
7 Warringah 89.0 1358 Entire home/apt
8 Rockdale 104.0 330 Entire home/apt
9 Randwick 94.0 1921 Entire home/apt
10 Canterbury 83.0 141 Entire home/apt
11 Sutherland Shire 109.0 388 Entire home/apt
12 Ku-Ring-Gai 81.0 170 Entire home/apt
13 Blacktown 87.0 72 Entire home/apt
14 Marrickville 69.0 685 Entire home/apt
15 Woollahra 134.0 1087 Entire home/apt
16 Willoughby 83.0 339 Entire home/apt
17 Ashfield 95.0 140 Entire home/apt
18 Hurstville 140.0 78 Entire home/apt
19 Ryde 86.0 284 Entire home/apt
20 Botany Bay 97.0 236 Entire home/apt
21 Burwood 89.0 78 Entire home/apt
22 Hornsby 133.0 208 Entire home/apt
23 Canada Bay 89.0 256 Entire home/apt
24 Campbelltown 168.0 60 Entire home/apt
25 Auburn 140.0 343 Entire home/apt
26 Lane Cove 104.0 184 Entire home/apt
27 Penrith 129.0 82 Entire home/apt
28 Holroyd 134.0 27 Entire home/apt
29 Camden 125.0 20 Entire home/apt
30 The Hills Shire 157.0 107 Entire home/apt
31 Liverpool 127.0 83 Entire home/apt
32 Parramatta 103.0 225 Entire home/apt
33 Hunters Hill 283.0 41 Entire home/apt
34 Strathfield 103.0 58 Entire home/apt
35 Bankstown 102.0 79 Entire home/apt
36 City Of Kogarah 102.0 54 Entire home/apt
37 Fairfield 87.0 39 Entire home/apt
In [14]:
# Plotting avg_cost_data on a graph
plot_data = pd.DataFrame(tmp)
plot_data
plt.plot(plot_data["location"], plot_data["price"])
plt.xticks(plot_data["location"], rotation='vertical', fontsize=25)
plt.ylabel("Price", fontsize=50, labelpad=50)
plt.title("Entire Home/Apt Avg. Price", fontsize=50, pad=30)
plt.figure(figsize=(10,10))
Out[14]:
<Figure size 720x720 with 0 Axes>
<Figure size 720x720 with 0 Axes>
In [15]:
tmp = sortSuburb(listings, rt_list[2])
print_data = pd.DataFrame(tmp)
print_data.rename(columns={"count": "Available Rooms", "location": "Location", "price": "Avg. Price per night", "rtype": "Room Type"}, inplace=True)
print_data
Out[15]:
Location Avg. Price per night Available Rooms Room Type
0 Randwick 36.0 65 Shared room
1 Sydney 30.0 301 Shared room
2 Rockdale 27.0 17 Shared room
3 Manly 69.0 9 Shared room
4 Waverley 28.0 118 Shared room
5 Mosman 23.0 2 Shared room
6 The Hills Shire 10.0 1 Shared room
7 Lane Cove 25.0 6 Shared room
8 Hurstville 38.0 6 Shared room
9 City Of Kogarah 22.0 4 Shared room
10 Botany Bay 43.0 11 Shared room
11 Auburn 71.0 10 Shared room
12 Warringah 49.0 6 Shared room
13 Hornsby 110.0 1 Shared room
14 Woollahra 21.0 10 Shared room
15 Ryde 24.0 16 Shared room
16 Burwood 20.0 24 Shared room
17 Liverpool 294.0 2 Shared room
18 Willoughby 34.0 9 Shared room
19 Canada Bay 34.0 5 Shared room
20 Strathfield 63.0 9 Shared room
21 North Sydney 43.0 10 Shared room
22 Pittwater 170.0 2 Shared room
23 Parramatta 37.0 17 Shared room
24 Ku-Ring-Gai 56.0 7 Shared room
25 Canterbury 25.0 12 Shared room
26 Ashfield 12.0 23 Shared room
27 Marrickville 22.0 19 Shared room
28 Leichhardt 16.0 3 Shared room
29 Holroyd 27.0 6 Shared room
30 Fairfield 0.0 1 Shared room
31 Blacktown 9.0 1 Shared room
32 Sutherland Shire 65.0 1 Shared room
33 Bankstown 27.0 6 Shared room
34 Campbelltown 49.0 1 Shared room
35 Penrith 44.0 2 Shared room
In [16]:
# Plotting avg_cost_data on a graph
plot_data = pd.DataFrame(tmp)
plot_data
plt.plot(plot_data["location"], plot_data["price"])
plt.xticks(plot_data["location"], rotation='vertical', fontsize=25)
plt.ylabel("Price", fontsize=50, labelpad=50)
plt.title("Shared Room Avg. Price", fontsize=50, pad=30)
plt.figure(figsize=(20,10))
Out[16]:
<Figure size 1440x720 with 0 Axes>
<Figure size 1440x720 with 0 Axes>

Get All Rental Locations Below Avg. Price in Sydney Suburb for Entire Home / Apt.

In [17]:
# Function to find the cheapest rental associated to the suburb and
# the given room type, returns a list on success
def sortCheapRentals(main_data, priceInfo, suburb, rtype):
    output = []
    
    maxLen = len(main_data["neighbourhood"])
    min_date = datetime(2018, 1, 1)
    
    for x in range(maxLen):
        # Gets daily price 
        dprice = main_data["price"][x] / main_data["minimum_nights"][x]
        
        # Check if date_str is not NULL object, if NULL continue
        if isinstance(main_data["last_review"][x], str) != True: 
            continue

        # Converts string into date type
        curr_date = datetime.strptime(main_data["last_review"][x], "%Y-%m-%d")
        
        # Check if neighbourhood matches 
        if main_data["neighbourhood"][x] == suburb:
            
            # Check if room_type matches rtype, if not continue
            if main_data["room_type"][x] != rtype:
                continue
            
            # Check if rental date is valid and price is lower than average
            # If not valid continue
            if curr_date < min_date:
                continue
                
            if main_data["availability_365"][x] >= 300 and dprice < findAvgPrice(priceInfo, suburb):
                new_dict = {
                    "id" : main_data["id"][x],
                    "name" : main_data["name"][x],
                    "host_id": main_data["host_id"][x],
                    "location" : main_data["neighbourhood"][x],
                    "rtype" : main_data["room_type"][x],
                    "price" : round(dprice),
                    "location_avg_price": findAvgPrice(priceInfo, suburb),
                    "availability" : main_data["availability_365"][x],
                    "min_night" : main_data["minimum_nights"][x]
                }
                output.append(new_dict);
    
    return output

# Function to find the avg price of a suburb from a given list
def findAvgPrice(priceInfo, suburb):
    
    for x in range(len(priceInfo["location"])):
        if priceInfo["location"][x] == suburb:
            return priceInfo["price"][x]
    
    return 0
In [18]:
# Call sortSuburbs to get average price info
priceInfo = sortSuburb(listings, rt_list[1])
priceInfo = pd.DataFrame(priceInfo)

sydney = sortCheapRentals(listings, priceInfo, "Sydney", rt_list[1])
sydney = pd.DataFrame(sydney)
sydney.rename(columns={"id": "Id", "location": "Location", 
                       "price": "Price/Night", "rtype": "Room Type",
                       "host_id": "Host_Id", "location_avg_price" : "Location Avg. Price",
                       "availability": "Availability", "min_night" : "Minimum Night"}, 
                       inplace=True)
sydney
Out[18]:
Id name Host_Id Location Room Type Price/Night Location Avg. Price Availability Minimum Night
0 288671 Warehouse Loft Conversion 241834 Sydney Entire home/apt 100.0 111.0 329 2
1 386997 Beautiful 2 Bedroom Apt Min Walk to the City 1936434 Sydney Entire home/apt 30.0 111.0 328 7
2 410073 Sydney Opera House-20min walk 2041405 Sydney Entire home/apt 57.0 111.0 307 3
3 465977 Surry Hills Oasis in the Inner City 77867 Sydney Entire home/apt 67.0 111.0 309 4
4 498008 In The Heart of Sydney CBD ! WIFI 2351093 Sydney Entire home/apt 90.0 111.0 302 3
5 658720 Paris End Potts Point HARBOUR VIEW! 1820335 Sydney Entire home/apt 60.0 111.0 300 2
6 686805 FAB SELF CONTAINED STUDIO IN SYDNEY 3437247 Sydney Entire home/apt 44.0 111.0 329 3
7 867805 Mantra Apartment Best Location Syd City Centre 4566859 Sydney Entire home/apt 21.0 111.0 346 7
8 869512 Charming cottage 4581304 Sydney Entire home/apt 29.0 111.0 360 5
9 949950 Bright Stylish Rushcutters Bay LOFT 2311627 Sydney Entire home/apt 94.0 111.0 360 2
10 1030731 1 Bdr EASTERN SUBURBS + CAR SPACE 3428692 Sydney Entire home/apt 43.0 111.0 344 3
11 1121918 UrbanOasis Studio in heart of city 6155676 Sydney Entire home/apt 20.0 111.0 351 7
12 1141803 unique sanctuary surry hills 97616 Sydney Entire home/apt 86.0 111.0 328 3
13 1350519 2 Bedroom terrace 5min from buzzing Crown St 6710987 Sydney Entire home/apt 50.0 111.0 305 5
14 1408891 Glebe 2 Bd city views /parking 7598416 Sydney Entire home/apt 75.0 111.0 361 4
15 1516013 Your Domain for Two in Newtown 8094649 Sydney Entire home/apt 70.0 111.0 331 2
16 1704217 Chic One bedroom near Hyde Park 8996869 Sydney Entire home/apt 9.0 111.0 349 14
17 1765417 Large 1BD apt min walk to the city 9277614 Sydney Entire home/apt 33.0 111.0 341 5
18 1769186 A Unique Potts Point Hideaway 2430835 Sydney Entire home/apt 53.0 111.0 346 3
19 1774070 Private apt in Cosmopolitan Newtown 8094649 Sydney Entire home/apt 78.0 111.0 344 2
20 1774193 Elms in the heart of Newtown 8094649 Sydney Entire home/apt 62.0 111.0 303 4
21 1866006 Sydney Darling Harbour & Chinatown 9359294 Sydney Entire home/apt 92.0 111.0 342 2
22 1975244 Potts Point, Pool and Harbour views 9549389 Sydney Entire home/apt 107.0 111.0 358 7
23 2095386 MODERN in style 1BR Apartment 10649195 Sydney Entire home/apt 10.0 111.0 302 14
24 2419091 Self-Contained Studio Apartment! 12363831 Sydney Entire home/apt 16.0 111.0 352 7
25 2484129 Sydney Best LUXURY Studio Apt 10649195 Sydney Entire home/apt 21.0 111.0 324 7
26 2561006 Central Sydney Self Contained ArtDeco Apartment. 10007090 Sydney Entire home/apt 55.0 111.0 339 2
27 2673807 Citypad with Spanish Character 1900555 Sydney Entire home/apt 78.0 111.0 352 2
28 3037737 Chinatown 2 level, 2 bdrm, 2 bathrm gym, pool ... 15469257 Sydney Entire home/apt 37.0 111.0 345 7
29 3212135 Executive unit-Fabulous views! 16272879 Sydney Entire home/apt 32.0 111.0 342 6
... ... ... ... ... ... ... ... ... ...
328 31163691 Renovated comfort in historic inner-city enclave 36410227 Sydney Entire home/apt 83.0 111.0 349 3
329 31318060 Duffotel Luxe Paddington Apartment 234423891 Sydney Entire home/apt 87.0 111.0 342 2
330 31418663 Character Filled CBD Apartment with Pool & Gym 97424788 Sydney Entire home/apt 38.0 111.0 357 4
331 31445696 Studio near Darling Harbour Pool & Gym 808g 15469257 Sydney Entire home/apt 2.0 111.0 364 90
332 31464378 Peaceful designer oasis in the heart of the city 36410227 Sydney Entire home/apt 73.0 111.0 352 3
333 31467258 Central artistic 1 bed apartment with views 36410227 Sydney Entire home/apt 57.0 111.0 343 3
334 31473506 Contemporary Apartment In Best Sydney Location 36410227 Sydney Entire home/apt 52.0 111.0 363 3
335 31559938 Spacious retreat walking distance from city ce... 36410227 Sydney Entire home/apt 73.0 111.0 341 3
336 31601969 NEW City Stay, Darling Harbour, Sydney 30570449 Sydney Entire home/apt 99.0 111.0 317 1
337 31672530 Chic city pad in Art Deco Bldg 10 min walk to CBD 98567543 Sydney Entire home/apt 70.0 111.0 326 2
338 31693492 FULLY FURNISHED SPACIOUS UNIT IN PYRMONT 208203244 Sydney Entire home/apt 38.0 111.0 315 3
339 31818896 Unbeatably located Art Deco Surry Hills studio 36410227 Sydney Entire home/apt 32.0 111.0 349 3
340 31838075 Freshly Renovated 3 Bed House in Heart of Newtown 238611546 Sydney Entire home/apt 90.0 111.0 329 2
341 32092315 Rennie House Luxury Inner City Get Away 205358810 Sydney Entire home/apt 80.0 111.0 321 2
342 32380970 Large Converted Church Apartment In Top Location 36410227 Sydney Entire home/apt 86.0 111.0 323 3
343 32402018 Sophisticated renovated terrace in fashion hub 36410227 Sydney Entire home/apt 83.0 111.0 323 3
344 32452784 1 Bedroom Apartment on Gloucester Street, Sydney 156409670 Sydney Entire home/apt 51.0 111.0 357 5
345 32492162 Renovated heritage terrace in unbeatable location 36410227 Sydney Entire home/apt 70.0 111.0 347 3
346 32682376 360 degrees Harbour Views, Now with car parking! 5031322 Sydney Entire home/apt 99.0 111.0 354 1
347 32794521 Sleek modern apartment close to everything 36410227 Sydney Entire home/apt 58.0 111.0 357 3
348 32929456 Sunny Studio in Darlinghurst 227959384 Sydney Entire home/apt 32.0 111.0 314 3
349 33375492 Modern & sophisticated top floor retreat 42532176 Sydney Entire home/apt 37.0 111.0 316 4
350 33430465 2 bedrm 2 bathrm apartment in convenient location 251429214 Sydney Entire home/apt 49.0 111.0 365 3
351 33480425 Luxury garden apartment in resort style building 14739318 Sydney Entire home/apt 93.0 111.0 302 3
352 33503109 'Mike’s On Mac' - Trendy Inner City Accomodation 7190634 Sydney Entire home/apt 50.0 111.0 306 2
353 33914765 Bright corner apartment only a stroll from the... 36410227 Sydney Entire home/apt 47.0 111.0 331 3
354 34093872 Large Apartment, 2 Parking Spots and Heated Pool 227194135 Sydney Entire home/apt 110.0 111.0 307 1
355 34916516 Trendy Studio Apartment in Roslyn Gardens Prec... 190379422 Sydney Entire home/apt 33.0 111.0 334 3
356 34960200 All in one Large CBD Studio 256301274 Sydney Entire home/apt 77.0 111.0 327 2
357 36341221 DARLING HARBOUR APARTMENT WITH FREE PARKING 273277604 Sydney Entire home/apt 95.0 111.0 316 2

358 rows × 9 columns

Gets List of Active Rentals (2018-2019)

In [19]:
# The difference between this function and the one above
# is that this one looks throughout the year 2018-2019
# Function to get the most recent rental of (year-2019)
# Returns a list of id's & associated geo data
def getRecentLocation(main_data, year):
    
    min_date = datetime(year, 1, 1)
    
    output = []
    maxLen = len(main_data["last_review"])
    
    for x in range(maxLen):
        
        #Check if date_str is not NULL object, if NULL continue
        if isinstance(main_data["last_review"][x], str) != True: 
            continue
            
        # Converts string into date type
        new_date = datetime.strptime(main_data["last_review"][x], "%Y-%m-%d")
        
        if new_date >= min_date:
            new_dict = {
                "id" : main_data["id"][x],
                "geometry" : main_data["geometry"][x],
                "date" : main_data["last_review"][x]
            }
            output.append(new_dict)
            
    return output
In [20]:
# Get information for recent reviews 2018-2019
recent_id = getRecentLocation(listings, 2018)
recent_id = pd.DataFrame(recent_id)
recent_geo = gp.GeoDataFrame(recent_id) # Convert recent_id into geopanda data frame

# IMPORTANT SETUP to ensure we are able to plot two DataFrame in the same graph
f, ax = plt.subplots(1, figsize=(40, 50))
ax.set_axis_off()
plt.axis('equal')
suburbs.plot(ax=ax, cmap='cool', linewidth=0.5)
recent_geo.plot(markersize=15, categorical=True, legend=True, ax=ax, cmap="winter",edgecolor='black');

plt.figtext(.5,.85,"All AirBnb Past Rental, 2018-2019",fontsize=50,ha='center')
Out[20]:
Text(0.5, 0.85, 'All AirBnb Past Rental, 2018-2019')

Bar graph showing places with Highest Rent Count

In [21]:
# Function to get popularity of renting in diff neighbourhoods
# returns a list on success
def checkPopularity(main_data):
    output = []
    
    maxLen = len(main_data["neighbourhood"])
    
    for x in range(maxLen):
        if checkSameLocation(main_data["neighbourhood"][x], output) == 0:
            new_dict = {
                "location" : main_data["neighbourhood"][x],
                "reviews" : main_data["number_of_reviews"][x],
            }
            output.append(new_dict)
        elif checkSameLocation(main_data["neighbourhood"][x], output) == 1:
            for i in output:
                if i["location"] == main_data["neighbourhood"][x]:
                    i["reviews"] += main_data["number_of_reviews"][x]
                    
    return output
    

# To ensure we don't create duplicate neighbourhoods
def checkSameLocation(loc, out):
    
    if not loc:
        return 0
    
    for x in out:
        if x["location"] == loc:
            return 1
    
    return 0


popRanking = checkPopularity(listings)
popRanking = pd.DataFrame(popRanking)
    
# Plotting reviews on graph
plot_data = popRanking

plt.plot(plot_data["location"], plot_data["reviews"])
plt.xticks(plot_data["location"], rotation='vertical', fontsize=25)
plt.ylabel("No. of Reviews", fontsize=50, labelpad=50)
plt.title("Suburbs", fontsize=50, pad=30)
plt.figure(figsize=(20,10))
Out[21]:
<Figure size 1440x720 with 0 Axes>
<Figure size 1440x720 with 0 Axes>